<?php
class SkillsController extends AppController {

	var $name = 'skills';
	var $helpers = array('Html', 'Form');
	
    function index_admin() 
    {
        if($this->Session->read('User.type')=='admin')
        {
            $this->layout = 'ajax';
            if(!empty($this->data))
            { 
                if($this->data['Skill']['name'] == '' )
                {
                    $this->set('empty',true);
                }
                else                
                if(!empty($this->data['Skill']['id']))
                {
                    $count = $this->Skill->find('count',array('conditions'=>array('Skill.name'=>$this->data['Skill']['name'],'Skill.id <>'=>$this->data['Skill']['id'])));
                    if( $count == 0 ) 
                    { $this->Skill->save($this->data); }
                    else
                    { $this->set('wrong',true); }
                }
                else
                {
                    $count = $this->Skill->find('count',array('conditions'=>array('Skill.name'=>$this->data['Skill']['name'])));
                    if( $count == 0 ) 
                    { 
                        $this->Skill->create(); 
                        $this->Skill->save($this->data);
                    }                
                    else
                    {
					$this->set('wrong',true);
					}
                }
            }
            $this->Skill->recursive=-1;
            $skills = $this->Skill->find('all',array('order'=>'Skill.name'));
			// var_dump($skills);
            $this->set('skills',$skills);
        }     
    }
	function delete_admin($id)
    {  
        if($this->Session->read('User.type')=='admin')
        {
            $this->layout = 'ajax';
            $this->Skill->del($id);
            $this->redirect(array('controller'=>'skills','action'=>'index_admin'));
        }        
    }
}
?>
